package com.sc.demo.plugins;

import java.sql.Statement;
import java.util.Properties;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.log4j.Logger;

@Intercepts({
	@Signature(type = StatementHandler.class, method = "update", args = { Statement.class })	
})
public class StatementUpdatePlugin implements Interceptor {
	
	private Logger logger = Logger.getLogger(StatementUpdatePlugin.class);
	
	public Object intercept(Invocation invocation) throws Throwable {
		logger.debug("[StatementUpdatePlugin] SQLStatement = " + ((Statement)invocation.getArgs()[0]));
		logger.debug("[StatementUpdatePlugin] method=" + invocation.getMethod());
		((Statement)invocation.getArgs()[0]).getConnection().setReadOnly(false);
		return invocation.proceed();
	}

	public Object plugin(Object target) {
		return Plugin.wrap(target, this);
	}

	public void setProperties(Properties properties) {
	}
}
